<template>
  <el-popover
      placement="bottom"
      width="40%"
      v-model:visible="showPopover"
      trigger="click">
    <template #reference>
      <div class="iconItem">
        <div v-if="icon">
          <unicon :name="icon.name" :fill="icon.fill" :icon-style="icon.iconStyle" />
          <span class="colors">{{icon}}</span>
        </div>
        <div v-else>
          <img style="width: 20px" src="@/assets/img/glass/album.png" alt="">
          <span>请选择图标</span>
        </div>
      </div>
    </template>
    <div class="search">
      <div class="search_input">
        <el-input
            placeholder="请输入图标名称"
            v-model="keyword"
            @input="searchKw"
            @blur="searchKw"
            @clear="clearIconPpopver"
            clearable >
        </el-input>
      </div>
      <div class="search_view" >
        <div v-for="item in IconsNameS" class="icon_item">
          <unicon :name="item" fill="blue" icon-style="line" />
          <span>{{item}}</span>
        </div>
      </div>
    </div>
  </el-popover>
</template>


<script setup>
import { ElPopover, formEmits } from 'element-plus'
import { computed, reactive, watch, ref, onMounted } from 'vue'
import IconsNameS from '@/util/UnIcons.js'

const props = defineProps({
  icon:{
    type:Object,
    default:{}
  },
  unIconFill:{
    type:String,
    default:'red'
  },
  unIconStyle:{
    type:String,
    default:'line'
  },
})
const menuIcons = ref([])
const icon = ref()
const showPopover = ref(false)
const keyword = ref('')

const searchKw = ()=>{

}
const clearIconPpopver = ()=>{

}
// 搜索图标
// const searchKw = () => {
//   if(!menuIcons.value) return
//   let list = menuIcons.value.filter(item => {
//     return item.indexOf(keyword.value) >= 0
//   })
//   menuIcons.value = list
// }
// onMounted(() => {menuIcons.value = menuIcon})
// const emit = defineEmits(['selected'])
//
// // 选择图标
// const changeIcons = ( item) => {
//   icon.value = item
//   keyword.value = ''
//   showPopover.value = false
//   emit('selected',icon.value)
// }
//
// // 关闭
// const clearIconPpopver = () => {
//   keyword.value = ''
//   menuIcons.value = []
// }
// watch([ keyword, ()=>props.icon],( newVal, oldVal ) => {
//   icon.value = newVal[1]
//   if(!keyword.value) menuIcons.value = menuIcon
//   let list = menuIcons.value.filter(item => {
//     return item.indexOf(keyword.value) >= 0
//   })
//   menuIcons.value = list
// },{immediate:true})
</script>

<style lang="scss" scoped>
.search_view {
  display: flex;
  width: 100%;
  .icon_item {
    width: 300px;
    height: 20px;
  }
}
</style>


